package com.ti.shangou.service.impl;

import com.ti.shangou.dao.MerchantDao;
import com.ti.shangou.pojo.dto.PageDTO;
import com.ti.shangou.pojo.dto.ResponseDTO;
import com.ti.shangou.pojo.entity.Merchant;
import com.ti.shangou.pojo.query.MerchantQuery;
import com.ti.shangou.pojo.vo.MerchantVO;
import com.ti.shangou.service.MerchantService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 作者：田宝山
 * 日期：2020/6/4
 */
@Service
public class MerchantServiceImpl implements MerchantService {
    @Resource
    MerchantDao merchantDao;

    public Object add(Merchant merchant){
        return ResponseDTO.get(merchantDao.insertSelective(merchant)==1);
    }


    public PageDTO ajaxList(MerchantQuery query) {
        List<MerchantVO> merchantVOList =  merchantDao.selectMerchantByQuery(query);
        Integer count = merchantDao.selectMerchantCount();
        return PageDTO.setPageData(count,merchantVOList);
    }

    public ResponseDTO editMerchant(Merchant merchant){
        return ResponseDTO.get(merchantDao.updateByPrimaryKeySelective(merchant)==1);
    }

    public MerchantVO selectMerchantIdByUserId(Long userId){
        return merchantDao.selectMerchantByUserId(userId);
    }

}
